<template>
  <div class="home">
    <img alt="Vue logo" src="../assets/logo.png" />
    <!-- <HelloWorld msg="Welcome to Your Vue.js + TypeScript App"/> -->
  </div>
</template>

<script >
import { reactive, toRefs, onMounted } from "vue";

import { api1, api2, api3 } from "@/utils/api"; // 导入我们的api接口
import { setCookie, getCookie } from "@/utils/cookieUtil";

export default {
  setup() {
    const state = reactive({
      inTheaters: [],
      comingSoon: [],
      top250: [],
    });

    const getInTheatersDate = async () => {
      const res = await getInTheaters({ start: 0, count: 10 });
      console.log(res.data);
    };
    const apiGet = async () => {
      // 调用api接口，并且提供了两个参数
      api2({
        // type: 0,
        // sort: 1
      })
        .then((res) => {
          // success
          console.log(res);
        })
        .catch((error) => {
          // error
          console.log(error);
        });
    };
    const apiPost = async () => {
      // 调用api接口，并且提供了两个参数
      let postData = {
        tel: "wangming",
        pwd: "12345678",
      };
      api3(postData)
        .then((res) => {
          // success
          console.log(res);
          setCookie("userName", postData.tel);
          setCookie("userPwd", postData.pwd);
        })
        .catch((error) => {
          // error
          console.log(error);
        });
    };
    onMounted(() => {
      // getInTheatersDate()
      apiPost();
    });

    return {
      ...toRefs(state),
    };
  },
};
</script>
